package com.bdq.common.utils;

import cn.hutool.core.util.StrUtil;
import com.bdq.common.exception.ServerException;

/**
 * @author malei
 * @date 2024-05-04 09:13
 */
public class IdempotentUtil {

    /**
     * 幂等
     *
     * @param redisKey
     * @param idempotentTimeWithSecond
     */
    public static void idempotent(String redisKey, Long idempotentTimeWithSecond) {
        String idempotent = RedisUtil.get(redisKey);
        if (StrUtil.isNotBlank(idempotent)) {
            throw new ServerException("请勿重复操作");
        }
        RedisUtil.setWithSecond(redisKey, redisKey, idempotentTimeWithSecond);
    }
}
